<template>
	<view class="container">
		<uni-card v-for="(item, index) in list" :key="index" :title="item.name" thumbnail="" :extra="item.date"
			:note="item.title">
			<text>{{item.content}}</text>
		</uni-card>
		<uni-load-more :status="loadStatus" @clickLoadMore="loadmore"
			:contentText="{contentdown: '显示更多', contentrefresh: '正在加载...', contentnomore: '没有更多数据了'}"></uni-load-more>

		<!-- 添加评论按钮 -->
		<uni-fab horizontal="right" vertical="bottom" :popMenu="false" @fabClick="addComment"></uni-fab>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				pageIndex: 0,
				pageSize: 10,
				hasMore: true
			}
		},
		onLoad() {
			this.loadFirstPage();
		},
		onPullDownRefresh() {
			this.pageIndex = 0;
			this.hasMore = true;
			this.loadFirstPage();
		},
		onReachBottom() {
			if (this.hasMore) {
				this.pageIndex++;
				this.loadmore();
			}
		},
		methods: {
			loadFirstPage() {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/message/listByPage',
					method: 'POST',
					data: {
						"offset": 1,
						"pageIndex": this.pageIndex,
						"pageSize": this.pageSize
					},
					success: res => {
						console.log(res);
						if (res.data.success) {
							this.list = res.data.data;
							if (this.list.length < this.pageSize) {
								this.hasMore = false;
							}
						} else {
							uni.showToast({
								title: '加载失败',
								icon: 'none'
							});
						}
					},
					fail: () => {
						uni.showToast({
							title: '请求失败',
							icon: 'none'
						});
					},
					complete: () => {
						uni.stopPullDownRefresh();
						uni.hideLoading();
					}
				});
			},
			loadmore() {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/message/listByPage',
					method: 'POST',
					data: {
						"offset": 1,
						"pageIndex": this.pageIndex,
						"pageSize": this.pageSize
					},
					success: res => {
						console.log(res);
						if (res.data.success) {
							this.list = this.list.concat(res.data.data);
							if (res.data.data.length < this.pageSize) {
								this.hasMore = false;
							}
						} else {
							uni.showToast({
								title: '加载失败',
								icon: 'none'
							});
						}
					},
					fail: () => {
						uni.showToast({
							title: '请求失败',
							icon: 'none'
						});
					}
				});
			},
			addComment() {
				uni.navigateTo({
					url: '/pages/pl/fbly'
				});
			}
		}
	}
</script>





<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>